package com.source.tiershop.server;

import javax.xml.datatype.XMLGregorianCalendar;

import webservices.framework.affilinet.svc.authentication.AuthenticationContract;
import webservices.framework.affilinet.svc.authentication.AuthenticationContractGetIdentifierExpirationAffilinetWebserviceFaultFaultFaultMessage;
import webservices.framework.affilinet.svc.authentication.AuthenticationContractGetIdentifierExpirationValidationFaultFaultFaultMessage;
import webservices.framework.affilinet.svc.authentication.AuthenticationContractLogonAffilinetWebserviceFaultFaultFaultMessage;
import webservices.framework.affilinet.svc.authentication.AuthenticationContractLogonValidationFaultFaultFaultMessage;
import webservices.framework.affilinet.svc.product.GetShopListRequest;
import webservices.framework.affilinet.svc.product.ProductServiceContract;
import webservices.framework.affilinet.svc.product.ProductServiceContractGetShopListProductDataFaultFaultFaultMessage;
import webservices.framework.affilinet.svc.product.ProductServices;
import webservices.framework.affilinet.types.WebServiceTypes;
import webservices.framework.affilinet.types.productservice.ShopList;

public class ProductWrapper {
	
	static ProductServiceContract proxy = null;
	
	private static webservices.framework.affilinet.svc.product.ObjectFactory svcProductObjectFactory =
	            				new webservices.framework.affilinet.svc.product.ObjectFactory();
	private static webservices.framework.affilinet.types.productservice.ObjectFactory typesProductObjectFactory =
								new webservices.framework.affilinet.types.productservice.ObjectFactory();

	public static void installProductServiceContract() {
		/*
		 Create the service endpoint interface
	     */
	    webservices.framework.affilinet.svc.product.ProductServices service =
	            new webservices.framework.affilinet.svc.product.ProductServices();
	    /*
	    Create a proxy out of the service endpoint interface
	     */
	    proxy = service.getPort(ProductServiceContract.class);
	    
	   /*
	   Create typed request message which will be used in the service call
	    */
	}
	
	
	public static ShopList getShopList() {
		
		
		if (proxy == null)
		{
			installProductServiceContract();
		}
		
	   GetShopListRequest request = svcProductObjectFactory.createGetShopListRequest();
	
	   
	   request.setCredentialToken(svcProductObjectFactory.createGetShopListRequestCredentialToken(AuthenticationWrapper.getCredentialToken()));
	   
	   /*
	   call the service method and process the result
	    */
	   ShopList shopList = null;
	   
		try {
			shopList = proxy.getShopList(request);
		} catch (ProductServiceContractGetShopListProductDataFaultFaultFaultMessage e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 

		
		return shopList;
	}

}